.PHONY: all target_dir boot framework libcommon modules clean qemu qemu-smp qemu-net qemu-gdb

export P_BASE  ?= ${PWD}
export V       ?= @
export MODDIR ?= modules

include ${P_BASE}/global/utils/make/cmds

all: target_dir target/boot.img

target_dir:
	@$(call C_MKDIR,${P_BASE}/target,-p)

boot:
	${V}$(call C_MAKE,boot,)

framework:
	${V}$(call C_MAKE,framework,)

libcommon:
	${V}$(call C_MAKE,libcommon,)

modules:
	${V}$(call C_MAKE,modules,)

target/boot.img: boot framework
	${V}$(call C_SH,${P_BASE}/global/utils/make_img.sh)

qemu: all
#-drive file=target/mod_main_user,media=disk,cache=writeback
	${V}qemu target/boot.img -m 512 -vga std -s -serial file:target/ekf.out

qemu-smp: all
	${V}qemu target/boot.img -smp 4 -m 512 -vga std -s -serial file:target/ekf.out

qemu-net: all
	${V}sudo qemu target/boot.img -net nic,model=e1000 -net tap -m 512 -s -serial file:target/ekf.out

target/usbdisk.img:
	${V}dd if=/dev/zero of=$@ bs=512 count=10000 2>/dev/null

qemu-usb: all target/usbdisk.img
	${V}qemu target/boot.img -m 512 -vga std -s -serial file:target/ekf.out -usb -usbdevice tablet
# -drive id=usb_disk,file=target/usbdisk.img,if=none -device usb-storage,drive=usb_disk

qemu-gdb: 
	${V}gdb --command=gdbinit

bochs: all
	${V}bochs -f bochsrc

bochs-smp: all
	${V}bochs -f bochsrc-smp

stat:
	${V}$(call C_SH,${P_BASE}/global/utils/loc.sh)

clean:
	-${V}${RM} target/* -rf

